package com.we.tickets.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class Redis {
    private static RedisTemplate<String, String> stringRedisTemplate;

    @Autowired
    public void setStringRedisTemplate(RedisTemplate<String, String> stringRedisTemplate) {
        Redis.stringRedisTemplate = stringRedisTemplate;
    }

    public static void set(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value);
    }

    public static String get(String key) {
        Object value = stringRedisTemplate.opsForValue().get(key);
        if (value == null) {
            return null;
        } else {
            return (String) value;
        }
    }
}
